package main

import "fmt"

func main() {

	root := &node{
		key: 1,
		next: &node{
			key: 2,
			next: &node{
				key: 3,
				next: &node{
					key:  4,
					next: nil,
				},
			},
		},
	}

	nodePrint(root)

	reversedNode := reverseNode(root)
	nodePrint(reversedNode)
}

func reverseNode(head *node) *node {
	if head.next == nil {
		return head
	}
	ret := reverseNode(head.next)
	head.next.next = head
	head.next = nil
	return ret
}

type node struct {
	key  int
	next *node
}

func nodePrint(node *node) {
	for node != nil {
		fmt.Printf("%d->", node.key)
		node = node.next
	}
	fmt.Printf("nil\n")
}
